--获取票的id和用户的id
local ticketId = ARGV[1]
local relativeId = ARGV[2]
local childrenId = ARGV[3]
--拼接键
local ticket = "action:ticket:" .. ticketId
local orderRelative = "action:order:relative:" .. ticketId
local orderChildren = "action:order:children:" .. ticketId
--判断当前库存是否充足
if(tonumber(redis.call("GET", ticket)) <= 0) then
    return 1
end

--判断大人用户是否下过单
if (redis.call("sismember",orderRelative,relativeId)==1) then
    return 2
end

--判断小孩用户是否下过单
if (redis.call("sismember",orderChildren,childrenId)==1) then
    return 3
end

--扣减库存,添加订单
redis.call("incrby",ticket,-1)
redis.call("sadd",orderRelative,relativeId)
redis.call("sadd",orderChildren,childrenId)

return 0